-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add jwks caching #1
Conversation
Warning Rate limit exceeded@DanielRivers has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 50 minutes and 18 seconds before requesting another review. How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThe changes introduce enhanced JWT verification by incorporating a cache for JSON Web Key Sets (JWKS). This involves fetching and caching JWKS to optimize verification processes and optionally forcing JWKS fetches. The tests have been updated to validate this caching mechanism and ensure proper functionality. Changes
Sequence Diagram(s) (Beta)sequenceDiagram
participant Client
participant Main
participant Utils
participant JWKSProvider
Client->>Main: verifyJwt(token, domain, forceJWKSFetch)
alt forceJWKSFetch is true or JWKS not cached
Main->>Utils: getJWKS(domain)
Utils->>JWKSProvider: Fetch JWKS
JWKSProvider-->>Utils: Return JWKS
Utils-->>Main: Return JWKS
Main->>Main: Cache JWKS
else JWKS cached
Main->>Main: Retrieve JWKS from cache
end
Main->>Main: Verify token using JWKS
Main-->>Client: jwtValidationResponse
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Outside diff range and nitpick comments (2)
lib/main.ts (1)
12-30
: The implementation ofverifyJwt
function with caching and force fetching is correct. Consider adding comments to explain the caching logic and the recursive call mechanism for better maintainability.lib/main.test.ts (1)
85-106
: The test case for caching JWKS correctly sets up the scenario and verifies the behavior. Consider adding assertions to ensure that the correct JWKS is used from the cache during the validation process.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
package.json
is excluded by!**/*.json
Files selected for processing (3)
- lib/main.test.ts (2 hunks)
- lib/main.ts (2 hunks)
- lib/utils.ts (1 hunks)
Additional comments not posted (3)
lib/utils.ts (1)
5-7
: The implementation ofgetJWKS
function looks correct and efficient.lib/main.ts (2)
1-2
: The imports and type declarations are correctly implemented and necessary for JWT verification functionality.
Line range hint
32-50
: ThevalidateToken
function is well-implemented, handling edge cases for missing token or domain effectively.
93bac2e
to
06d6b7e
Compare
06d6b7e
to
5be5858
Compare
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered ☂️ |
Explain your changes
feat: adds caching to so doesn't need to over request the JWSK from the well knowns
Checklist
🛟 If you need help, consider asking for advice over in the Kinde community.